<template>
    <el-popover placement="bottom" trigger="click" v-model="popShow" width="232" popper-class='col_pop' @hide="closePopover">
        <slot name="title"></slot>
        <el-checkbox-group v-model="checkList" @click.native="clickUserJumpIdState" :min="1">
            <div v-for="(item) in disposeGroup" :key="item.label" class="group_div">
                <el-checkbox :label="item.label" style="width:100%">{{item.name}}</el-checkbox>
            </div>
        </el-checkbox-group>
        <div class="operate">
            <el-button size="mini" @click="popShow = false,handleBtn(0)">取 消</el-button>
            <el-button type="primary" size="mini" @click="popShow = false,handleBtn(1)">确 定</el-button>
        </div>
        <slot name="dispose_btn" slot="reference"></slot>
    </el-popover>
</template>

<script>
    export default {
        data() {
            return {
                popShow: false,
                checkList: [],
                beforeChangeList: [],
                changeDiposeGroup: [],
            }
        },
        props: {
            disposeGroup: {
                type: Array,
                default: () => []
            },
            minNum: {
                type: String,
                default: ''
            }
        },
        mounted() {
        },
        watch: {
            checkList:{
                handler(val){
                    this.changeDiposeGroup = val
                },
                immediate:true
            },
            disposeGroup: {
                handler(nVal, oVal) {
                    this.disposeGroup = nVal
                    this.checkAll()
                },
                deep: true
            }
        },
        methods: {
            //默认全选
            checkAll() {
                this.checkList = []
                this.disposeGroup.forEach(item => {
                    if(item.state == true) {
                        this.checkList.push(item.label)
                    }
                })
            },
            clickUserJumpIdState() {
                this.beforeChangeList = this.checkList
            },
            closePopover() {
                this.checkList = []
                this.checkAll()
            },
            // 取消--确定
            handleBtn(type) {
                //点击取消先将数组置空
                if(type == 0){
                    this.checkList = []
                    this.checkAll()
                }else{
                    this.$emit('handleChangeDiposeGroup', this.changeDiposeGroup)
                }
            },
        }
    }
</script>
